<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/page/layout/layout.xhtml" 
                xmlns="http://www.w3.org/1999/xhtml" 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="title">Login</ui:define>
    <ui:define name="content">        
        <p:growl id="mensajes" showDetail="true" life="2000" />
        <h:form>
            <p:panel header="Login" style="width:300px">
                <h:panelGrid columns="2" cellpadding="5">
                    <h:outputLabel for="username" value="Usuario:" />
                    <p:inputText value="#{loginBean.nombre}" id="username"
                                 required="true" label="username" />
                    <h:outputLabel for="password" value="Clave:" />
                    <p:password value="#{loginBean.clave}" id="password" required="true"
                                label="password" />
                    <f:facet name="footer">
                        <p:commandButton id="loginButton" value="Login"
                                         actionListener="#{loginBean.login}" update=":mensajes"
                                         oncomplete="manejarLogin(xhr, status, args)" />
                    </f:facet>
                </h:panelGrid>
            </p:panel>
        </h:form>
        <script type="text/javascript">
            //<![CDATA[
            function manejarLogin(xhr, status, args) {
                if (!args.validationFailed && args.estaLogeado) {
                    setTimeout(function() {
                        window.location = args.view;
                    }, 500);
                }
            }
//]]>
        </script>
    </ui:define>
</ui:composition>
